﻿using GraphProcessor;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.ChangeSceneEffect, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_ChangeSceneEffect : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.ChangeSceneEffect;

        public override string name => LevelEditorConst.ChangeSceneEffect;
        [Output("目标", false)] public EditorLevelServiceTargetSetter tagOrMcid;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.ChangeSceneEffect, "LevelSceneEffect表ID")]
        public int effectCid;
        [InspectorName("是否是添加"), Tooltip("否为移除")] public bool isAdd;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_ChangeSceneEffect()
            {
                // tagOrMcid = this.tagOrMcid,
                effectCid = this.effectCid,
                isAdd = this.isAdd
            };
            this.tagOrMcid = new EditorLevelServiceTargetSetter(x => rConfig.tagOrMcid = x);
            return rConfig;
        }

        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_ChangeSceneEffect rNode)
            {
                this.isAdd = rNode.isAdd;
                this.effectCid = rNode.effectCid;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_ChangeSceneEffect rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid);
            }
        }
    }
}